const mongoose = require('mongoose');

// 任务模式
const taskSchema = new mongoose.Schema({
  id: String,
  title: String,
  description: String,
  type: String,
  reward: {
    greenEnergy: Number,
    carbonReduction: Number,
    trees: Number,
    waterQuality: Number
  },
  progress: {
    type: Number,
    default: 0
  },
  completed: {
    type: Boolean,
    default: false
  },
  deadline: Date,
  criteria: {
    type: {
      type: String,
      enum: ['steps', 'energy', 'action', 'participation']
    },
    target: Number,
    current: {
      type: Number,
      default: 0
    }
  }
});

// 活动模式
const activitySchema = new mongoose.Schema({
  id: String,
  date: {
    type: Date,
    default: Date.now
  },
  category: String,
  description: String,
  value: Number
});

const userSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    unique: true,
    trim: true
  },
  email: {
    type: String,
    required: true,
    unique: true,
    trim: true,
    lowercase: true
  },
  password: {
    type: String,
    required: true
  },
  carbonFootprint: {
    type: Number,
    default: 25
  },
  greenEnergy: {
    type: Number,
    default: 100
  },
  planetState: {
    pollution: {
      type: Number,
      default: 30
    },
    biodiversity: {
      type: Number,
      default: 70
    },
    energy: {
      clean: {
        type: Number,
        default: 30
      },
      total: {
        type: Number,
        default: 100
      }
    },
    buildings: [{
      type: String
    }],
    trees: {
      type: Number,
      default: 100
    },
    waterQuality: {
      type: Number,
      default: 80
    }
  },
  achievements: [{
    type: String
  }],
  tasks: [taskSchema],
  activities: [activitySchema],
  createdAt: {
    type: Date,
    default: Date.now
  }
});

module.exports = mongoose.model('User', userSchema); 